<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
<head>
    <title>代理商管理系统</title>
    <link rel="stylesheet" type="text/css" href="${ctx}/statics/easyui/themes/default/easyui.css" />
    <link rel="stylesheet" type="text/css" href="${ctx}/statics/easyui/themes/icon.css" />
    <link rel="stylesheet" type="text/css" href="${ctx}/statics/easyui/themes/color.css" />
    <link rel="stylesheet" type="text/css" href="${ctx}/statics/easyui/themes/demo.css" />
    <script src="${ctx}/statics/easyui/jquery.min.js" type="text/javascript"></script>
    <script src="${ctx}/statics/easyui/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="${ctx}/statics/easyui/easyui-lang-zh_CN.js" type="text/javascript"></script>
</head>
<body class="easyui-layout" >
    <div id="tool" data-options="region:'north',border:false" style="width:100%;height:50px;line-height:50px;background:#eee;text-align:center">
        <a href="${ctx}/do/toAddCustomPage" class="easyui-linkbutton"
           data-options="iconCls:'icon-add',size:'small'" style="margin-right:20px">新增客户</a>
        <span style="font-size:13px">搜索客户:</span>
        <input id="search" style="width:200px;height:24px;" />
    </div>
    <div id="data" data-options="region:'center',border:false" style="width:100%;" >
        <table id="dg" style="width:100%;"></table>
    </div>
    <script>
        //页面加载请求当前登陆用户的客户列表
        $(
            function ()
            {
                var customDatagrid = $("#dg").datagrid
                (
                    {
                        url:'${ctx}/do/showAgentCustomManage',
                        fitColumns:true,
                        striped:true,
                        fit:true,
                        rownumbers:true,
                        pagination:true, //增加分页工具栏
                        pageNumber:1, //设置初始化页码
                        pageSize:10,  //页大小
                        pageList:[5,10,15], //显示数量选择
                        columns:
                            [
                                [
                                    {field:'id',title:'序号',width:'12%',align:'center'},
                                    {field:'customName',title:'企业名称',width:'12%',align:'center'},
                                    {field:'bossName',title:'法人代表',width:'12%',align:'center'},
                                    {field:'regDatetime',title:'注册时间',width:'15%',align:'center'},
                                    {field:'customTypeName',title:'类型',width:'12%',align:'center'},
                                    {field:'customStatus',title:'状态',width:'12%',align:'center',
                                        formatter: function(value,row,index)
                                        {
                                            return ( value?"启用":"未启用" );
                                        },
                                        styler: function(value,row,index)
                                        {
                                            return ( value?"color:green":"color:red" );
                                        }

                                    },
                                    {field:'control',title:'操作', width:'23%', align:'center',
                                        formatter: function(value,row,index)
                                        {
                                            var str = '<a href="javascript:void(null)" class="easyui-linkbutton" onclick="viewCustom(' + row.id + ')" ' +
                                                ' data-options="iconCls:\'icon-edit\',size:\'small\'" style="text-decoration:none" >查看</a>' + '&nbsp;&nbsp;&nbsp;&nbsp;' +
                                                '<a href="javascript:void(null)" class="easyui-linkbutton" onclick="editCustom(' + row.id + ')" ' +
                                                ' data-options="iconCls:\'icon-edit\',size:\'small\'" style="text-decoration:none" >修改</a>' + '&nbsp;&nbsp;&nbsp;&nbsp;' +
                                                '<a href="javascript:void(null)" class="easyui-linkbutton" onclick="stopOrStartCustom(' + row.id + ',' + row.customStatus + ')" ' +
                                                ' data-options="iconCls:\'icon-remove\',size:\'small\'" style="text-decoration:none">';
                                            str += (row.customStatus?'停用</a>':'启用</a>');
                                            return str;
                                        }
                                    }
                                ]
                            ]
                    }
                );

                //点击搜索客户根据客户名进行模糊搜索
                $("#search").textbox(
                    {
                        buttonText:'搜索',
                        buttonIcon:'icon-search',
                        prompt:'请输入客户名搜索',
                        onClickButton:function ()
                        {
                            //获取要搜索的客户名称
                            var customName = $("#search").textbox('getValue');
                            //将输入的客户名加入请求参数中
                            //因customDatagrid的原设置中已包含url,故无需reload
                            customDatagrid.datagrid(
                                {
                                    queryParams: {"customName":customName}
                                }
                            );
                        }
                    }
                );

            }
        );

        //点击编辑客户发送请求
        function editCustom( customId )
        {
            window.location.href = "${ctx}/do/toUpdateCustomPage?customId=" + customId;
        }

        //点击查看客户发送请求
        function viewCustom( customId )
        {
            window.location.href = "${ctx}/do/toViewCustomPage?customId=" + customId;
        }

        //点击停用客户发送请求
        function stopOrStartCustom( customId , status )
        {
            var title = (status?'停用用户':'启用用户');
            var info =  (status?'您确定要停用该用户吗?':'您确定要启用该用户吗?');
            var action = (status?'stopCustom':'startCustom');
            $.messager.confirm(title,info,
                    function( r )
                    {
                        //点击确定发送修改状态请求
                        if ( r )
                        {
                            $.ajax(
                                {
                                    url:'${ctx}/do/enableOrDisableCustom',
                                    type:"POST",
                                    data:{"action":action,"customId":customId},
                                    dataType:"json",
                                    success:function ()
                                    {
                                        $("#dg").datagrid('reload');
                                    }
                                }
                            )

                        }
                    });
        }

    </script>

</body>
</html>
